package com.cf.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cf.common.result.Result;
import com.cf.system.dto.MenuDTO;
import com.cf.system.entity.TopMenu;
import com.cf.system.service.MenuService;
import com.cf.system.service.TopMenuService;
import com.cf.system.vo.MenuVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ChenFeng
 * @date 2021/11/4 6:45 下午
 * @description
 */
@RestController
@RequestMapping("/menu")
@AllArgsConstructor
public class MenuController {

    private final MenuService menuService;

    private final TopMenuService topMenuService;

    @GetMapping("/auth-routes")
    public Result<List<Map<String, List<String>>>> authRoutes() {
        List<Map<String, List<String>>> menuDTOList = menuService.authRoutes();
        return Result.success(menuDTOList);
    }

    @GetMapping("/top-menu")
    public Result topMenu() {
        List<TopMenu> list = topMenuService.list(Wrappers.<TopMenu>query().lambda().orderByAsc(TopMenu::getSort));
        return Result.success(list);
    }

    @GetMapping("/routes")
    public Result<List<MenuVO>> routes(){
        List<MenuVO> menuVOS = menuService.routers();
        return Result.success(menuVOS);
    }

    @GetMapping("/buttons")
    public Result<List<MenuVO>> buttons() {
        List<MenuVO> list = menuService.buttons();
        return Result.success(list);
    }

}
